<template>
  <div class="login-container">
    <div class="login-card">
      <h2>登录</h2>
      <input v-model="username" placeholder="用户名" />
      <input v-model="password" type="password" placeholder="密码" />
      <button @click="handleLogin">登录</button>
      <p v-if="errorMsg" class="error">{{ errorMsg }}</p>
      <p class="demo-tip">
        演示账号:<br />
        用户名: admin, 密码: admin123<br />
        用户名: user, 密码: 123456
      </p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useAuthStore } from '../stores/auth';

const username = ref('');
const password = ref('');
const errorMsg = ref('');

const auth = useAuthStore();
const router = useRouter();

const handleLogin = async () => {
  const success = await auth.login(username.value, password.value);
  if (success) {
    router.push('/todo');
  } else {
    errorMsg.value = '用户名或密码错误';
  }
};
</script>

<style scoped>
/* 整体容器样式 */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  /* 使用二次元常用的渐变背景 */
  background: linear-gradient(135deg, #ffc0cb 0%, #87cefa 100%);
  /* 去掉滚动条 */
  overflow: hidden;
}

/* 登录卡片样式 */
.login-card {
  width: 350px;
  padding: 2rem;
  border-radius: 20px;
  /* 使用半透明背景增加梦幻感 */
  background-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  text-align: center;
  /* 添加一些动画效果 */
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-15px);
  }
  100% {
    transform: translateY(0px);
  }
}

/* 标题样式 */
h2 {
  font-family: 'Comic Sans MS', cursive, sans-serif;
  color: #ff69b4;
  font-size: 2.5em;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  margin-bottom: 1.5rem;
}

/* 输入框样式 */
input {
  display: block;
  width: calc(100% - 24px); /* 减去内边距 */
  padding: 12px;
  margin: 1rem auto; /* 垂直外边距和水平居中 */
  border-radius: 15px;
  border: 2px solid #87cefa;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  font-size: 1em;
  /* 输入框获得焦点时的样式 */
  outline: none;
  transition: border-color 0.3s ease;
}

input:focus {
  border-color: #ff69b4;
}

/* 按钮样式 */
button {
  width: 100%;
  padding: 12px;
  background-color: #ff69b4;
  color: white;
  border: none;
  border-radius: 15px;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  font-size: 1.2em;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease;
  margin-top: 1.5rem;
}

button:hover {
  background-color: #ff1493;
  transform: scale(1.05);
}

/* 错误信息样式 */
.error {
  color: #ff4500;
  margin-top: 15px;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  font-size: 0.9em;
}

/* 演示账号提示样式 */
.demo-tip {
  font-family: 'Comic Sans MS', cursive, sans-serif;
  font-size: 0.9em;
  color: #333;
  margin-top: 1.5rem;
}
</style>